import java.util.ArrayList;
import java.util.Collections;

/*
 * Class Question.
 * Stores question, answers, and hint. Supports all methods of ArrayList. Arguments are required when creating object.
 * Supports variable number of correct and incorrect answers. Method addAndShuffle must be used if answers need to be randomised.
 * Keeps track of score and total number of possible correct answers.
 */
public class Question extends ArrayList<Answer> {

	private String question;
	private String hint;
	private int totalCorrect;
	
	private Question() {}
	
	public Question(String question, String hint) {
		this.question = question;
		this.hint = hint;
		totalCorrect = 0;
	}

	public String getQuestionText() {
		return question;
	}
	
	public boolean addAndShuffle(Answer answer){
		boolean ret = super.add(answer);
		shuffle();
		if (answer.isCorrect()) totalCorrect++;
		return ret;
	}
	
	public boolean addAndShuffle(String answerText, boolean correct){
		boolean ret = super.add(new Answer(answerText, correct));
		shuffle();
		if (correct) totalCorrect++;
		return ret;
	}
	
	public String getAnswerTextOf(int index) {
		return get(index).getAnswerText();
	}
	
	public boolean isCorrectAnswer(int index) {
		return get(index).isCorrect();
	}
	
	public String getHintText() {
		return hint;
	}
	
	public int getTotalCorrect() {
		return totalCorrect;
	}
	
	public int getScore() {
		int score = 0;
		for (int i = 0; i < this.size(); i++) {
			if (get(i).isCorrect() && get(i).isSelected()) score++;
		}
		return score;
	}
	
	public void shuffle(){
		Collections.shuffle(this);
	}
	
}
